

function deleteElement(elementId) {

    $("#" + elementId).remove();
}


//激活tooltip
function enableTooptip() {
    
    $("[title]").tinyTips('light', 'title') //带有title的全部加提示
}

function generateUniqueStamp() {

    return Math.round(Math.random()*100000);
}

function generateErrorDialog(msg, title) {
    title  = typeof(title) != 'undefined' ? title : '啊呀，出错啦:('
    var uniquestamp = generateUniqueStamp()
    //create the unique div id
    var div_id = "dialog_error_" + uniquestamp;

    var dialog_str = "<div id='" + div_id + "' title='" + title + "' style='display:none'>"
    dialog_str += "<div class='ui-widget'>"
    dialog_str += "<div class='ui-state-error ui-corner-all' style='padding: 0 .7em;'>"
    dialog_str += "<p>"
    dialog_str += "<span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 50px 0;'></span>"
    dialog_str += "<strong>出错啦:</strong>" + msg
    dialog_str += "</p>"
    dialog_str += "</div>"
    dialog_str += "</div>"
    dialog_str += "</div>"

    return new Array(div_id, dialog_str)
    
}


function showErrorDialog(msg, title) {
    var dialog = generateErrorDialog(msg, title)
    //append dialog to webpage
    $("body").append(dialog[1])
    $("#" + dialog[0]).dialog({
        modal: true,
        buttons: {
            "确定": function() {
                //$(this).dialog('close')
                $(this).dialog('destroy')
                $("#" + dialog[0]).remove()
            }
        }
    });
}

//生成信息框内容
function generateInfoDialog(msg, title) {

    title  = typeof(title) != 'undefined' ? title : '请注意'
    var uniquestamp = generateUniqueStamp()
    //create the unique div id
    var div_id = "dialog_info_" + uniquestamp;

    var dialog_str = "<div id='" + div_id + "' title='" + title + "' style='display:none'>"
    dialog_str += "<div class='ui-widget'>"
    dialog_str += "<div class='ui-state-highlight ui-corner-all' style='margin-top: 20px; padding: 0 .7em;'>"
    dialog_str += "<p><span class='ui-icon ui-icon-info' style='float: left; margin-right: .3em;'></span>"
    dialog_str += "<strong>注意!</strong>" + msg
    dialog_str += "</p>"
    dialog_str += "</div>"
    dialog_str += "</div>"
    dialog_str += "</div>"

    return new Array(div_id, dialog_str)
    
}

//显示信息框
function showInfoDialog(msg, title) {
    var dialog = generateInfoDialog(msg, title)
    //append dialog to webpage
    $("body").append(dialog[1])
    $("#" + dialog[0]).dialog({
        modal: true,
        buttons: {
            "确定": function() {
                //$(this).dialog('close')
                $(this).dialog('destroy')
                $("#" + dialog[0]).remove()
            }
        }
    });
}

function generateConfirmDialog(msg, title) {
    
    title  = typeof(title) != 'undefined' ? title : '请确认该操作'
    var uniquestamp = generateUniqueStamp()
    //create the unique div id
    var div_id = "dialog_confirm_" + uniquestamp;

    var dialog_str = "<div id='" + div_id + "' title='" + title + "' style='display:none'>"
    //dialog_str += "<div id='dialog-confirm' title='" + title + "'>"
    dialog_str += "<p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 20px 0;'></span>"
    dialog_str += msg
    dialog_str += "</p>"
    dialog_str += "</div>"
    //dialog_str += "</div>"
    
    return new Array(div_id, dialog_str)
    
}


function showConfirmDialog(msg, title, confirmCallbackFunc) {

    var dialog = generateConfirmDialog(msg, title)
    $("body").append(dialog[1])

    $("#" + dialog[0]).dialog({
        resizable: false,
        height:140,
        modal: true,
        closeOnEscape: false,
        buttons: {
            '确定': function() {
                $(this).dialog('destroy')
                confirmCallbackFunc()
            },
            '取消': function() {
                $(this).dialog('destroy')
            }
        }
    });
     
}


function showLoadingBar(msg) {

    var loadingbar = generateLoadingBar(msg)
    $("#content").prepend(loadingbar[1])
    $("#" + loadingbar[0]).fadeIn()
    
    return loadingbar[0]    //返回载入状态条的id
}

function hideLoadingBar(loadingbar_id) {

    $("#" + loadingbar_id).fadeOut()
    $("#" + loadingbar_id).remove()
    
}

function generateLoadingBar(msg) {

    msg = typeof(msg) != 'undefined' ? msg : "载入中，请稍等......"
    var uniquestamp = generateUniqueStamp()
    var div_id = "loadingbar_" + uniquestamp
    var dialog_str = "<div id='" + div_id + "' align='center' style='display: none;'>"
    dialog_str += "<img src='/images/loadingAnimation.gif' /><br />"
    dialog_str += msg
    dialog_str += "</div>"

    return new Array(div_id, dialog_str)
}


function generateErrorBar(msg) {

    msg = typeof(msg) != "undefined" ? msg : "出错啦..."
    var uniquestamp = generateUniqueStamp()
    var div_id = "errorbar_" + uniquestamp

    var dialog_str = "<div id='" + div_id + "' style='display:none'>"
    dialog_str += "<div class='ui-widget'>"
    dialog_str += "<div class='ui-state-error ui-corner-all' style='padding: 0 .7em;'>"
    dialog_str += "<p>"
    dialog_str += "<span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 50px 0;'></span>"
    dialog_str += "<strong>出错啦:</strong>" + msg
    dialog_str += "</p>"
    dialog_str += "</div>"
    dialog_str += "</div>"
    dialog_str += "</div>"

    return new Array(div_id, dialog_str)
    
}

function showErrorBar(msg) {
    var errorbar = generateErrorBar(msg)
    $("#content").prepend(errorbar[1])
    $("#" + errorbar[0]).fadeIn()

}

function hideErrorBar(errorbar_id) {
    
    $("#" + errorbar_id).fadeOut()
    $("#" + errorbar_id).remove()
}

//Close All Error Bar and remove the element
function closeAllErrorBar() {

    $("div[id*=errorbar_]").remove()

}